#include <QApplication>
#include "CMainWindow.h"
#include <QFont>
#include "CConversion.h"
#include <QDebug>
#include "CUIHelper.h"
#include "CIconFont.h"
#include "VSettings.h"
#include "VHistory.h"
#include <QStyleFactory>
#include "DbConnectManager.h"
#include "CConfig.h"

int main(int argc, char *argv[])
{
#if(QT_VERSION >= QT_VERSION_CHECK(5,6,0))
    QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif

    QApplication a(argc, argv);

    //debug输出格式
    qSetMessagePattern("%{if-debug}[DBUG%{endif}"
                       "%{if-info}\033[32m[INFO%{endif}"
                       "%{if-warning}\033[33m[WARN%{endif}"
                       "%{if-critical}\033[31m[ERRO%{endif}"
                       "%{if-fatal}\033[35m[FATL%{endif}] "
                       "%{time yyyyMMdd h:mm:ss.zzz} "
                       "%{function}:%{line} - %{message}\033[0m");

    //生成版本信息
    a.setApplicationVersion(SUPERDT_VERSION);
    a.setProperty("UpdateDateTime",SUPERDT_UPDATE);

    qInfo()<<"App version:"<<a.applicationVersion()<<"UpdateDateTime:"<<a.property("UpdateDateTime").toString();

    QFont font;
    font.setFamily("等线,Arial");
    a.setFont(font);


    DbConnectManager::getInstance()->init(QApplication::applicationDirPath() + "/SuperDT.db");


    CIconFont::getInstance()->init(":/Font/iconfont.ttf");

    CConfig::getInstance()->init(); //初始化皮肤 语言

    CMainWindow::getInstance()->init();
    CMainWindow::getInstance()->resize(800,800);
    CMainWindow::getInstance()->show();


//    VHistory s;
//    s.show();
//    char *strText = "12345678";

//    int nVal;
//    nVal = CConversion::crc8((const unsigned char *)strText,strlen(strText));
//    qDebug("CRC 8:%x",nVal);

//    nVal = CConversion::crc16((const unsigned char *)strText,strlen(strText));
//    qDebug("CRC 16:%x",nVal);

//    nVal = CConversion::crc16MODBUS((const unsigned char *)strText,strlen(strText));
//    qDebug("CRC 16MODBUS:%x",nVal);

//    nVal = CConversion::crc16DNP((const unsigned char *)strText,strlen(strText));
//    qDebug("CRC 16DNP:%x",nVal);

    return a.exec();
}
